<?php

class GlistController extends CommonController{
	
	private $_model;
	
	public function __init(){
		
		$this->_model=K('glist');
	}
	
	public function index(){
		
		if(IS_POST){
			
			$this->_model->add_data();
			$this->success('添加成功');
			
		}
		
		$gid=Q('get.gid');
		$data=$this->_model->get_all_data(array('gid'=>$gid));
		
//		p($data);die;
		foreach ($data as $k => $v) {
			$data[$k]['apid']=explode(',', $v['apid']);
			foreach ($data[$k]['apid'] as $key => $value) {
				$data[$k]['apid'][$key]=K('Gproperty')->get_gpvalue(array('gpid'=>$value));
				$data[$k]['apid'][$key]=implode(',', $data[$k]['apid'][$key]);
			}
		}
		
		
		
		$this->assign('data',$data);
		$where='gid="' . $gid .'" and tptype = "规格"';
		$tpid=K('GTpropertyView')->get_all_data($where,'tproperty.tpid');
		$arr=array();
		foreach ($tpid as $k => $v) {
			$arr[]=$v['tpid'];
		}
		$add_spec=array();
		foreach ($arr as $k => $v) {
			
			$where='gid="' . $gid .'" and tptype = "规格' .'" and tproperty.tpid = ' . $v ;
			$add_spec[]=K('GTpropertyView')->get_all_data($where);
		}
//		p($add_spec);
		
		
		$this->assign('add_spec',$add_spec);
		$this->assign('tpid',$tpid);
		
		$this->display();
	}


	public function del(){
		
		$this->_model->del_data(array('glid'=>Q('get.glid')));
		
		$this->success('删除成功');
	}






}







